package main

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

//定义模型
type User struct {
	ID           int64
	Name         string
	Age          int64
}

func main()  {
	db, err := gorm.Open("mysql", "root:root@(127.0.0.1)/test?charset=utf8mb4&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	//创建表 自动迁移
	//db.AutoMigrate(&User{})

	//user := User{ID:1, Name:"Liuck33", Age: 18}
	//user := User{Name:"Liuck33", Age: 18}

	//创建
	//db.Create(&user)

	//更新
	var user User
	db.First(&user)

	user.Name = "火影"
	//user.Age = 99
	//db.Debug().Save(&user)
	//db.Debug().Model(&user).Update("name", "naruto")

	u1 := map[string]interface{}{
		"name" : "lili",
		"age" : 28,
	}
	db.Debug().Model(&user).Updates(u1)

}
